#ifndef FGE_TEXTUREPACKER_HPP
#define FGE_TEXTUREPACKER_HPP

#include <list>

namespace fge
{

struct Node
{
	int x, y;
	int width, height;
	int index;
	Node *left, *right;
};

class TexturePacker
{
public:
	TexturePacker(int padding);
	~TexturePacker();

	void AddTexture(int width, int height);
	void PackTextures(int &textureWidth, int &textureHeight);
	void GetDataByIndex(int index, int &x, int &y, int &width, int &height);

private:
	bool TryPackTextures(int textureWidth, int textureHeight);
	void FreeNode(Node *node);
	bool InsertTexture(Node *node, Node *texture);
	Node* GetNodeByIndex(Node *node, int index);

	int padding;
	Node *root;
	std::list<Node> textures;
};

}

#endif//FGE_TEXTUREPACKER_HPP
